home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / QuakeTools / src / util / qtools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  9.4 KB  |  407 lines

  1. #define    LIBQTOOLS_CORE
  2. #include <libqtools.h>
  3.  
  4. /*
  5.  * global vars
  6.  */
  7.  
  8. int main(int argc, char **argv) {
  9.   int i;
  10.   char *outName = 0, *destDir = 0;
  11.   bool script = TRUE;
  12.   bool recurse = FALSE;
  13.   operation procOper = OP_DEFAULT;
  14.   unsigned char outType = TYPE_UNKNOWN;
  15.   unsigned char arcType = TYPE_UNKNOWN;
  16.  
  17.   /* 
  18.    * definition of interation:
  19.    *  if there is some to put out, use that specific type
  20.    *  else if there is some to get in, use the same specific type
  21.    */
  22.   for (i = 1; i < argc; i++) {
  23.     if (!strcmp(argv[i], "-p")) {
  24.       /*
  25.        * palette-file 
  26.        */
  27.       argv[i] = 0;
  28.       palFile = fopen(argv[++i], READ_BINARY);
  29.       argv[i] = 0;
  30.     }
  31.     else if (!strcmp(argv[i], "-c")) {
  32.       /*
  33.        * colormap-file 
  34.        */
  35.       argv[i] = 0;
  36.       colrFile = fopen(argv[++i], READ_BINARY);
  37.       argv[i] = 0;
  38.     }
  39.     else if (!strcmp(argv[i], "-pp")) {
  40.       /*
  41.        * colormap-file 
  42.        */
  43.       argv[i] = 0;
  44.       preProcessor = argv[++i];
  45.       argv[i] = 0;
  46.     }
  47.     else if (!strcmp(argv[i], "-d")) {
  48.       /*
  49.        * dest-dir 
  50.        */
  51.       argv[i] = 0;
  52.       destDir = argv[++i];
  53.       argv[i] = 0;
  54.     }
  55.     else if (!strcmp(argv[i], "-l")) {
  56.       /*
  57.        * darkness-level 
  58.        */
  59.       char *tmp;
  60.  
  61.       argv[i] = 0;
  62.       darkness = strtol(argv[++i], &tmp, 0);
  63.       argv[i] = 0;
  64.     }
  65.     else if (!strcmp(argv[i], "-o")) {
  66.       /*
  67.        * specify output-name 
  68.        */
  69.       argv[i] = 0;
  70.       outName = argv[++i];
  71.       argv[i] = 0;
  72.     }
  73.     else if (!strcmp(argv[i], "-ppm")) {
  74.       /*
  75.        * convert to ppm 
  76.        */
  77.       argv[i] = 0;
  78.       outType = TYPE_PPM;
  79.     }
  80.     else if (!strcmp(argv[i], "-jpg")) {
  81.       /*
  82.        * convert to jpg
  83.        */
  84.       argv[i] = 0;
  85.       outType = TYPE_JPEG;
  86.     }
  87.     else if (!strcmp(argv[i], "-iff")) {
  88.       /*
  89.        * convert to iff
  90.        */
  91.       argv[i] = 0;
  92.       outType = TYPE_ILBM;
  93.     }
  94.     else if (!strcmp(argv[i], "-png")) {
  95.       /*
  96.        * convert to png
  97.        */
  98.       argv[i] = 0;
  99.       outType = TYPE_PNG;
  100.     }
  101.     else if (!strcmp(argv[i], "-vis")) {
  102.       /*
  103.        * create vis information
  104.        */
  105.       argv[i] = 0;
  106.       arcType = TYPE_VIS;
  107.     }
  108.     else if (!strcmp(argv[i], "-watervis")) {
  109.       /*
  110.        * create vis information
  111.        */
  112.       argv[i] = 0;
  113.       watervis = TRUE;
  114.     }
  115.     else if (!strcmp(argv[i], "-slimevis")) {
  116.       /*
  117.        * create vis information
  118.        */
  119.       argv[i] = 0;
  120.       slimevis = TRUE;
  121.     }
  122.     else if (!strcmp(argv[i], "-waterlit")) {
  123.       /*
  124.        * create vis information
  125.        */
  126.       argv[i] = 0;
  127.       waterlit = TRUE;
  128.     }
  129.     else if (!strcmp(argv[i], "-nofill")) {
  130.       /*
  131.        * create vis information
  132.        */
  133.       argv[i] = 0;
  134.       nofill = TRUE;
  135.     }
  136.     else if (!strcmp(argv[i], "-notjunc")) {
  137.       /*
  138.        * create vis information
  139.        */
  140.       argv[i] = 0;
  141.       notjunc = TRUE;
  142.     }
  143.     else if (!strcmp(argv[i], "-noclip")) {
  144.       /*
  145.        * create vis information
  146.        */
  147.       argv[i] = 0;
  148.       noclip = TRUE;
  149.     }
  150.     else if (!strcmp(argv[i], "-onlyents")) {
  151.       /*
  152.        * create vis information
  153.        */
  154.       argv[i] = 0;
  155.       onlyents = TRUE;
  156.     }
  157.     else if (!strcmp(argv[i], "-verbose")) {
  158.       /*
  159.        * create vis information
  160.        */
  161.       argv[i] = 0;
  162.       verbose = TRUE;
  163.     }
  164.     else if (!strcmp(argv[i], "-fastvis")) {
  165.       /*
  166.        * create vis information
  167.        */
  168.       argv[i] = 0;
  169.       fastvis = TRUE;
  170.     }
  171.     else if (!strcmp(argv[i], "-usehulls")) {
  172.       /*
  173.        * qbsp
  174.        */
  175.       argv[i] = 0;
  176.       usehulls = TRUE;
  177.     }
  178.     else if (!strcmp(argv[i], "-scale")) {
  179.       /*
  180.        * qbsp-scale
  181.        */
  182.       argv[i] = 0;
  183.       scale = atof(argv[++i]);
  184.       argv[i] = 0;
  185.     }
  186.     else if (!strcmp(argv[i], "-range")) {
  187.       /*
  188.        * qbsp-scale
  189.        */
  190.       argv[i] = 0;
  191.       range = atof(argv[++i]);
  192.       argv[i] = 0;
  193.     }
  194.     else if (!strcmp(argv[i], "-vislevel")) {
  195.       /*
  196.        * vis-level 
  197.        */
  198.       char *tmp;
  199.  
  200.       argv[i] = 0;
  201.       vislevel = strtol(argv[++i], &tmp, 0);
  202.       argv[i] = 0;
  203.     }
  204.     else if (!strcmp(argv[i], "-hullnum")) {
  205.       /*
  206.        * qbsp-hullnum
  207.        */
  208.       char *tmp;
  209.  
  210.       argv[i] = 0;
  211.       hullnum = strtol(argv[++i], &tmp, 0);
  212.       argv[i] = 0;
  213.     }
  214.     else if (!strcmp(argv[i], "-subdivide")) {
  215.       /*
  216.        * qbsp-subdivide 
  217.        */
  218.       char *tmp;
  219.  
  220.       argv[i] = 0;
  221.       subdivide = strtol(argv[++i], &tmp, 0);
  222.       argv[i] = 0;
  223.     }
  224.     else if (!strcmp(argv[i], "-lit")) {
  225.       /*
  226.        * create vis information
  227.        */
  228.       argv[i] = 0;
  229.       arcType = TYPE_LIT;
  230.     }
  231.     else if (!strcmp(argv[i], "-mip")) {
  232.       /*
  233.        * convert to mip
  234.        */
  235.       argv[i] = 0;
  236.       /* set interaction to mip */
  237.       arcType = TYPE_MIPMAP;
  238.     }
  239.     else if (!strcmp(argv[i], "-wal")) {
  240.       /*
  241.        * convert to mip
  242.        */
  243.       argv[i] = 0;
  244.       /* set interaction to mip */
  245.       arcType = outType = TYPE_WAL;
  246.     }
  247.     else if (!strcmp(argv[i], "-lump")) {
  248.       /*
  249.        * convert to lump 
  250.        */
  251.       argv[i] = 0;
  252.       /* set interaction to lump */
  253.       arcType = TYPE_LUMP;
  254.     }
  255.     else if (!strcmp(argv[i], "-ns")) {
  256.       /*
  257.        * no scripting  
  258.        */
  259.       argv[i] = 0;
  260.       script = FALSE;
  261.     }
  262.     else if (!strcmp(argv[i], "-lz")) {
  263.       /*
  264.        * lz77 compression
  265.        */
  266.       argv[i] = 0;
  267.       Compression |= CMP_LZ77;
  268.     }
  269.     else if (!strcmp(argv[i], "-mip0")) {
  270.       /*
  271.        * lz77 compression
  272.        */
  273.       argv[i] = 0;
  274.       Compression |= CMP_MIP0;
  275.     }
  276.     else if (!strcmp(argv[i], "-dither")) {
  277.       /*
  278.        * dither ppm 
  279.        */
  280.       char *tmp;
  281.  
  282.       argv[i] = 0;
  283.       dither = TRUE;
  284.       if((argv[i + 1][0] != '-') && (argv[i + 1][0] >= '0') && (argv[i + 1][0] <= '9')) {
  285.         dithervalue = strtol(argv[++i], &tmp, 0);
  286.         argv[i] = 0;
  287.         if (dithervalue < 16)
  288.       dithervalue = 16;
  289.         if (dithervalue > 256)
  290.       dithervalue = 256;
  291.       }
  292.     }
  293.     else if (!strcmp(argv[i], "-smooth")) {
  294.       /*
  295.        * smooth ppm 
  296.        */
  297.       char *tmp;
  298.  
  299.       argv[i] = 0;
  300.       smoothing = TRUE;
  301.       if((argv[i + 1][0] != '-') && (argv[i + 1][0] >= '0') && (argv[i + 1][0] <= '9')) {
  302.         smoothingvalue = strtol(argv[++i], &tmp, 0);
  303.         argv[i] = 0;
  304.         if (smoothingvalue < 1)
  305.       smoothingvalue = 1;
  306.         if (smoothingvalue > 256)
  307.       smoothingvalue = 256;
  308.       }
  309.     }
  310.     else if (!strcmp(argv[i], "x")) {
  311.       /*
  312.        * extract the contents
  313.        */
  314.       argv[i] = 0;
  315.       procOper = OP_EXTRACT;
  316.     }
  317.     else if (!strcmp(argv[i], "a")) {
  318.       /*
  319.        * add the contents
  320.        */
  321.       argv[i] = 0;
  322.       procOper = OP_ADD;
  323.     }
  324.     else if (!strcmp(argv[i], "l")) {
  325.       /*
  326.        * list the contents
  327.        */
  328.       argv[i] = 0;
  329.       procOper = OP_LIST;
  330.     }
  331.     else if (!strcmp(argv[i], "-h")) {
  332.       mprintf("%s [-<options>] [<command>] <file> ...
  333.  
  334.   options :
  335.  
  336.    -c <colormap>       quake colormap lump
  337.    -d <destdir>        alternative destination directory
  338.    -dither [<value>]   dither floyd-steinberg with this error
  339.    -smooth [<value>]   smooth with this fraction
  340.    -l <darkness>       take this darkness
  341.    -lump/-mip          specifies pic-conversion (in general for directory-conversions without \"-o\")
  342.    -mip0               store only the first mip instead of all four (only for wads)
  343.    -lz                 compress data with lz77 (only for wads)
  344.    -ns                 do not write index-files
  345.    -o <file>           specify archive-content or output-name
  346.    -p <palette>        quake palette lump
  347.    -ppm/-jpg/-iff/-png convert pictures and palettes to ppm/jpg/iff/png
  348.    -r                  recurse extracting
  349.  
  350.   commands:
  351.  
  352.    a                   add
  353.    d                   delete (unimplemented)
  354.    l                   list (default)
  355.    r                   replace (unimplemented)
  356.    u                   update (unimplemented)
  357.    v                   view (unimplemented)
  358.    x                   extract
  359.  
  360.   examples:
  361.  
  362.    %s test.bsp test.pak test.wad test.mdl test.spr
  363.     list all the contents of all the files
  364.    %s x test.bsp test.pak test.wad test.mdl test.spr
  365.     extract all the contents of all the files to the directory test.dir (bad :)
  366.    %s x test1.bsp test2.pak test3.wad test4.mdl test/test5.spr
  367.     extract all the contents of all the files to the directories test1.dir
  368.     test2.dir test3.dir test4.dir test/test5.dir (good ;)
  369.    %s -o *lava1 x test1.bsp
  370.     extract the raw-mipmap-texture *lava1 to test1.dir/*lava1.mip
  371.    %s -d test -o *lava1 x test1.bsp
  372.     extract the raw-mipmap-texture *lava1 to test/test1.dir/*lava1.mip
  373.    %s -o *lava1 x test1.wad
  374.     extract the wad-content *lava1 to test1.dir/*lava1.<wad2-type>
  375.    %s -ppm -o *lava1 x test1.wad
  376.     extract the wad-content *lava1 to test1.dir/*lava1.ppm
  377.    %s -ppm -o *lava1.mip x test1.wad
  378.     extract the wad-content *lava1 to test1.dir/*lava1.mip with conversion to ppm
  379.     *lava1.mip is NOT a raw-mipmap-texture, its a PPM
  380.  
  381. (all rights reserved, Niels Froehling, Dyna-Tech 1998)
  382. ", argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]);
  383.       if (palFile)
  384.         fclose(palFile);
  385.       if (colrFile)
  386.         fclose(colrFile);
  387.       return 0;
  388.     }
  389.   }
  390.  
  391.   if(argc > 1) {
  392.     for (i = 1; i < argc; i++) {
  393.       if(argv[i]) {
  394.         processName(argv[i], destDir, outName, outType, 0, arcType, procOper, script, recurse);
  395.       }
  396.     }
  397.     if (palFile)
  398.       fclose(palFile);
  399.     if (colrFile)
  400.       fclose(colrFile);
  401.   }
  402.   else
  403.     mprintf("use -h for options\n");
  404.  
  405.   return 0;
  406. }
  407.